package com.example.demo;

import com.example.demo.jackson.JacksonFilter;
import com.example.demo.jackson.JacksonView;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.util.CookieGenerator;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/demo")
public class DemoController {

	//jackson view demo
    @ResponseBody
    @RequestMapping("/hello")
    @JacksonView(filters = @JacksonFilter(type = User.class, exclude = "age"))
    public User hello() {
        return new User("V", 27, new Address("11号街", 11));
    }

	//ignore
    @RequestMapping("/home")
    public String home(String code, String state, HttpServletResponse response, HttpSession session) {
        System.out.println("code = " + code + ", state = " + state);

        CookieGenerator cookieGenerator = new CookieGenerator();
        cookieGenerator.setCookiePath("/");
        cookieGenerator.setCookieHttpOnly(true);
        cookieGenerator.setCookieName("name");
        cookieGenerator.addCookie(response, "zhangsan");

        return "redirect:/home.html";
    }

}
